#include "manhattanCalc.h"
#include <cstdlib>


const int	manhattanCalc::calcScore(const int* now, const int* end, int size)
	{
	int i;
	int rez = 0;

	_size = size * size;
	for (i = 0; i < _size ; ++i)
		rez += calcdist(now[i], i, end, size);
	return rez;
	}

const int manhattanCalc::calcdist(const int num,const int pos, const int *final,const int size)
{
	int i;
	int rez;
	int tmp;

	for (i = 0; i < _size && num != final[i]; i++)
		;
	if (i == pos)
		return 0;
	tmp = abs(i / size - pos / size);
	rez = abs(i % size - pos % size);
	return (rez + tmp);
}